package com.starview.star.compiler.wff;

import com.starview.platform.data.type.Location;
import com.starview.star.compiler.ast.IAbstract;
import com.starview.star.compiler.ast.StringLiteral;
import com.starview.star.compiler.standard.StandardNames;
import com.starview.star.compiler.util.PrettyPrintDisplay;
import com.starview.star.compiler.wff.WffOp.applyMode;

@SuppressWarnings("serial")
public class WffWarning implements WffCond
{
  private final WffBuildOp val;

  public WffWarning(WffBuildOp val)
  {
    this.val = val;
  }

  @Override
  public applyMode satisfied(IAbstract env[], Location loc, WffEngine engine)
  {
    IAbstract tgt = val.build(env, loc, engine);

    if (tgt instanceof StringLiteral)
      engine.reportWarning(((StringLiteral) tgt).getLit(), loc);
    else
      engine.reportWarning(tgt.toString(), loc);
    return applyMode.validates;
  }

  @Override
  public void prettyPrint(PrettyPrintDisplay disp)
  {
    disp.append(StandardNames.WFF_WARNING);
    disp.append("(");
    val.prettyPrint(disp);
    disp.append(")");
  }
}
